#import "GKCover.h"
#import "dfhgwhruebvhrheysavingmuscular.h"
#import "dfhgwhruebvhrheyleisureinterference.h"
#import "dfhgwhruebvhrheymaintainlunarViewController.h"
#import "dfhgwhruebvhrheyspheredesign.h"
@interface dfhgwhruebvhrheymaintainlunarViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, copy) NSString *name;
@end
@implementation dfhgwhruebvhrheymaintainlunarViewController {
	UIView *bgView;
	UILabel *placeholder;
	UITextView *inputText;
	UIButton *iconBtn;
	UILabel *tipsLabel;
	UIView *uploadView;
	UIButton *submitBtn;
	UIButton *iconCloseBtn;
	UILabel *serviceTextLabel;
	void(^submitAction)(dfhgwhruebvhrheyleisureinterference *model);
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
}
- (void)loadUI {
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	self.view.backgroundColor = bg_color1.dhgfywegwygeydwlearneddesignate;
	bgView = [[UIView alloc] init];
	bgView.layer.cornerRadius = 10;
	bgView.backgroundColor = @"#F7F7F7".dhgfywegwygeydwlearneddesignate;
	[self.view addSubview:bgView];
	placeholder = [[UILabel alloc] init];
	placeholder.textColor = @"#AAAAAA".dhgfywegwygeydwlearneddesignate;
	placeholder.font = [UIFont regular:15];
	placeholder.text = @"Please write down your problem";
	[bgView addSubview:placeholder];
	inputText = [[UITextView alloc] init];
	inputText.backgroundColor = [UIColor clearColor];
	inputText.font = [UIFont regular:15];
	[bgView addSubview:inputText];
	uploadView = [[UIView alloc] init];
	[self.view addSubview:uploadView];
	iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	iconBtn.backgroundColor = @"#F7F7F7".dhgfywegwygeydwlearneddesignate;
	[iconBtn setImage:[UIImage imageNamed:@"mine_feedback_add"] forState:UIControlStateNormal];
	[iconBtn addTarget:self action:@selector(iconBtnAction:) forControlEvents:UIControlEventTouchUpInside];
	[uploadView addSubview:iconBtn];
	iconCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	[iconCloseBtn setImage:[UIImage imageNamed:@"mine_feedback_img_close"] forState:UIControlStateNormal];
	[iconCloseBtn addTarget:self action:@selector(iconCloseAction) forControlEvents:UIControlEventTouchUpInside];
	[uploadView addSubview:iconCloseBtn];
	iconCloseBtn.hidden = YES;
	tipsLabel = [[UILabel alloc] init];
	tipsLabel.font = [UIFont regular:15];
	tipsLabel.textColor = @"#AAAAAA".dhgfywegwygeydwlearneddesignate;
	tipsLabel.text = @"Upload photo for specification";
	[uploadView addSubview:tipsLabel];
	UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
	[tap addTarget:self action:@selector(tapAction)];
	[uploadView addGestureRecognizer:tap];
	submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	submitBtn.layer.cornerRadius = 10;
	submitBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	submitBtn.titleLabel.font = [UIFont semiBold:18];
	[submitBtn setTitle:@"Submit" forState:UIControlStateNormal];
	[submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[submitBtn addTarget:self action:@selector(submitBtnAction) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:submitBtn];
	serviceTextLabel = [[UILabel alloc] init];
	serviceTextLabel.font = [UIFont regular:15];
	serviceTextLabel.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	serviceTextLabel.textAlignment = NSTextAlignmentCenter;
	serviceTextLabel.text = @"Customer service online time：9:00-18:00";
	[self.view addSubview:serviceTextLabel];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inputDidChanged) name:UITextViewTextDidChangeNotification object:nil];
}
- (void)inputDidChanged {
	placeholder.hidden = inputText.text.length;
}
- (void)tapAction {
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	picker.modalPresentationStyle = UIModalPresentationFullScreen;
	[self presentViewController:picker animated:YES completion:nil];
}
- (void)submitBtnAction {
	[self.view endEditing:YES];
	if(inputText.text.length == 0) {
		return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please enter your problem"];
	}
	NSData *imgData = [dfhgwhruebvhrheysavingmuscular compressImage:self.image inKiloByte:300];
	dfhgwhruebvhrheyleisureinterference *model = [[dfhgwhruebvhrheyleisureinterference alloc] init];
	model.type = @"1";
	model.choe = @"Produce issue";
	model.cdata = inputText.text;
	model.img_data = [imgData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
	if(submitAction) {
		submitAction(model);
	}
}
- (void)submit:(void(^)(dfhgwhruebvhrheyleisureinterference *model))action {
	submitAction = action;
}
- (void)clean {
	self.name = nil;
	self.image = nil;
	inputText.text = nil;
	iconBtn.selected = NO;
	placeholder.hidden = NO;
	iconCloseBtn.hidden = YES;
	tipsLabel.text = @"Upload photo for specification";
	placeholder.text = @"Please write down your problem";
	[iconBtn setImage:[UIImage imageNamed:@"mine_feedback_add"] forState:UIControlStateNormal];
}
- (void)iconBtnAction:(UIButton *)sender {
	if (!sender.isSelected) {
		[self tapAction];
	}else {
		dfhgwhruebvhrheyspheredesign *popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheyspheredesign" owner:nil options:nil].firstObject;
		[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
		[popView bindImage:self.image andClose:^{
			[GKCover hideCover];
		}];
	}
}
- (void)iconCloseAction {
	iconBtn.selected = NO;
	iconCloseBtn.hidden = YES;
	[iconBtn setImage:[UIImage imageNamed:@"mine_feedback_add"] forState:UIControlStateNormal];
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.top.equalTo(self.view).offset(15);
		make.centerX.equalTo(self.view);
		make.height.mas_equalTo(160);
	}];
	[placeholder mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.top.equalTo(bgView).offset(15);
	}];
	[inputText mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(bgView).insets(UIEdgeInsetsMake(5, 10, 5, 10));
	}];
	[iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.top.equalTo(uploadView).offset(15);
		make.size.mas_equalTo(CGSizeMake(60, 60));
	}];
	[tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(iconBtn);
		make.left.equalTo(iconBtn.mas_right).offset(10);
	}];
	[iconCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(24, 24));
		make.top.equalTo(iconBtn).offset(-12);
		make.right.equalTo(iconBtn).offset(12);
	}];
	[uploadView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(bgView.mas_bottom).offset(15);
		make.left.centerX.equalTo(bgView);
		make.height.mas_equalTo(92);
	}];
	[uploadView drawBoardWithCornerRadius:10 andColor:@"#CCCCCC".dhgfywegwygeydwlearneddesignate];
	[submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(uploadView.mas_bottom).offset(44);
		make.left.centerX.equalTo(uploadView);
		make.height.mas_equalTo(50);
	}];
	[serviceTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.view);
		make.top.equalTo(submitBtn.mas_bottom).offset(40);
	}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
	self.image = info[UIImagePickerControllerOriginalImage];
	[iconBtn setImage:self.image forState:UIControlStateNormal];
	iconBtn.selected = YES;
	iconCloseBtn.hidden = NO;
	[picker dismissViewControllerAnimated:YES completion:nil];
}
@end
